/*
	Title: 02_Table9.do
	Paper: Brauning, Ivashina, Ozdagli (2025)
	Description: Table 9 - Robustness Analysis to EBITDA adjustments
*/

/*------------------------------------------------------------------------------
								 Table 9A
------------------------------------------------------------------------------*/
// Import Table 9A data --------------------------------------------------------
use "$data_path/Table9A_Stock_Comp.dta", clear


// Table Setup -----------------------------------------------------------------
putdocx clear 
putdocx begin
putdocx paragraph
putdocx table table9a = (17,5), border(insideV, nil) border(insideH, nil) border(left, nil) border(right, nil)

* Left margin
putdocx table table9a(4,1) = ("Incurrence covenant violation")
putdocx table table9a(6,1) = ("Maintenance covenant violation")
putdocx table table9a(9,1) = ("Observations")
putdocx table table9a(10,1) = ("R-squared")
putdocx table table9a(11,1) = ("Firm FE")
putdocx table table9a(12,1) = ("Quarter FE")
putdocx table table9a(13,1) = ("Controls")
putdocx table table9a(14,1) = ("Controls*Cov-type")
putdocx table table9a(15,1) = ("Quarter FE*Cov-type")
putdocx table table9a(16,1) = ("H0: Maintenance = Incurrence")
putdocx table table9a(17,1) = ("p-value")

* Top margin
putdocx table table9a(1,2), colspan(2)
putdocx table table9a(1,2) = ("Add stock-based compensation expense")
putdocx table table9a(1,3), colspan(2)
putdocx table table9a(1,3) = ("Add stock-based compensation and pension expenses")

putdocx table table9a(2,2) = ("(1)")
putdocx table table9a(2,3) = ("(2)")
putdocx table table9a(2,4) = ("(3)")
putdocx table table9a(2,5) = ("(4)")
putdocx table table9a(2,.), border(bottom)


// Define Regression Specifications --------------------------------------------
local LHS "capex_capital_ratio_tr"

local controls0   "L_macroq_tr L_logatq_tr cashflowq_tr" 
local dd_controls " L_DD_Total_final_tr L_DD_Total_final_sq_tr"
local controls    "`controls0' `dd_controls'"

local cond0 "L.dealscan <= 1"
local cond1 "_b1_diff_std <= 2 & _b2_diff_std <= 2"
local cond2 "(!mi(lev_limit) | !mi(intcov_limit) | !mi(Ilev_limit) | !mi(Iintcov_limit))"
local conditions "`cond0' & `cond1' & `cond2'"


// Column (1) ------------------------------------------------------------------
// Regression: 
reghdfe `LHS' L_Iin_covenant_violation L_Min_covenant_violation `controls' L_incurrence L_maintenance if `conditions', ///
			  absorb(xdim qdate) cluster(xdim qdate) 

// Store results 
matrix reg_results = r(table)
local incurrence_b : display %04.2f reg_results["b", "L_Iin_covenant_violation"]
local incurrence_se : display %04.2f reg_results["se", "L_Iin_covenant_violation"]
local incurrence_p = reg_results["pvalue", "L_Iin_covenant_violation"]

if (`incurrence_p' > 0.1) {
	local incurrence_sigstars = ""
} 
if (`incurrence_p' < 0.1) {
	local incurrence_sigstars = "*"
}
if (`incurrence_p' < 0.05) {
	local incurrence_sigstars = "**"
}
if (`incurrence_p' < 0.01) {
	local incurrence_sigstars = "***"
}

local maintenance_b : display %04.2f reg_results["b", "L_Min_covenant_violation"]
local maintenance_se : display %04.2f reg_results["se", "L_Min_covenant_violation"]
local maintenance_p = reg_results["pvalue", "L_Min_covenant_violation"]

if (`maintenance_p' > 0.1) {
	local maintenance_sigstars = ""
} 
if (`maintenance_p' < 0.1) {
	local maintenance_sigstars = "*"
}
if (`maintenance_p' < 0.05) {
	local maintenance_sigstars = "**"
}
if (`maintenance_p' < 0.01) {
	local maintenance_sigstars = "***"
}
local N = e(N)
local r2 : display %9.2f  e(r2)

* H0: Incurrence = Maintenance (results stored in r(estimate) and r(p))
lincom L_Min_covenant_violation - L_Iin_covenant_violation
local estimate = r(estimate)
local p: display %9.3f r(p)

// Put results into table in Word Document 
putdocx table table9a(4,2) = ("`incurrence_b'`incurrence_sigstars'")
putdocx table table9a(5,2) = ("(`incurrence_se')")
putdocx table table9a(6,2) = ("`maintenance_b'`maintenance_sigstars'")
putdocx table table9a(7,2) = ("(`maintenance_se')")
putdocx table table9a(9,2) = (`N')
putdocx table table9a(10,2) = (`r2')
putdocx table table9a(11,2) = ("Yes")
putdocx table table9a(12,2) = ("Yes")
putdocx table table9a(13,2) = ("Yes")
putdocx table table9a(14,2) = ("No")
putdocx table table9a(15,2) = ("No")
putdocx table table9a(16,2) = (`estimate')
putdocx table table9a(17,2) = (`p')
	
	
// Column (2) ------------------------------------------------------------------
// Regression: 
reghdfe `LHS' L_Iin_covenant_violation L_Min_covenant_violation (L_incurrence L_maintenance)##c.(`controls') if `conditions', ///
			  absorb(xdim L_incurrence#qdate L_maintenance#qdate) cluster(xdim qdate) 
	
// Store results 
matrix reg_results = r(table)
local incurrence_b : display %04.2f reg_results["b", "L_Iin_covenant_violation"]
local incurrence_se : display %04.2f reg_results["se", "L_Iin_covenant_violation"]
local incurrence_p = reg_results["pvalue", "L_Iin_covenant_violation"]

if (`incurrence_p' > 0.1) {
	local incurrence_sigstars = ""
} 
if (`incurrence_p' < 0.1) {
	local incurrence_sigstars = "*"
}
if (`incurrence_p' < 0.05) {
	local incurrence_sigstars = "**"
}
if (`incurrence_p' < 0.01) {
	local incurrence_sigstars = "***"
}

local maintenance_b : display %04.2f reg_results["b", "L_Min_covenant_violation"]
local maintenance_se : display %04.2f reg_results["se", "L_Min_covenant_violation"]
local maintenance_p = reg_results["pvalue", "L_Min_covenant_violation"]

if (`maintenance_p' > 0.1) {
	local maintenance_sigstars = ""
} 
if (`maintenance_p' < 0.1) {
	local maintenance_sigstars = "*"
}
if (`maintenance_p' < 0.05) {
	local maintenance_sigstars = "**"
}
if (`maintenance_p' < 0.01) {
	local maintenance_sigstars = "***"
}
local N = e(N)
local r2 : display %9.2f  e(r2)

* H0: Incurrence = Maintenance (results stored in r(estimate) and r(p))
lincom L_Min_covenant_violation - L_Iin_covenant_violation
local estimate = r(estimate)
local p: display %9.3f r(p)

// Put results into table in Word Document 
putdocx table table9a(4,3) = ("`incurrence_b'`incurrence_sigstars'")
putdocx table table9a(5,3) = ("(`incurrence_se')")
putdocx table table9a(6,3) = ("`maintenance_b'`maintenance_sigstars'")
putdocx table table9a(7,3) = ("(`maintenance_se')")
putdocx table table9a(9,3) = (`N')
putdocx table table9a(10,3) = (`r2')
putdocx table table9a(11,3) = ("Yes")
putdocx table table9a(12,3) = ("Yes")
putdocx table table9a(13,3) = ("Yes")
putdocx table table9a(14,3) = ("Yes")
putdocx table table9a(15,3) = ("Yes")
putdocx table table9a(16,3) = (`estimate')
putdocx table table9a(17,3) = (`p')
	
	
// Import Table 9A data	--------------------------------------------------------
use "$data_path/Table9A_Stock_Comp_Pension.dta", clear


// Column (3) ------------------------------------------------------------------
// Regression: 
reghdfe `LHS' L_Iin_covenant_violation L_Min_covenant_violation `controls' L_incurrence L_maintenance if `conditions', ///
			  absorb(xdim qdate) cluster(xdim qdate) 
	
// Store results 
matrix reg_results = r(table)
local incurrence_b : display %04.2f reg_results["b", "L_Iin_covenant_violation"]
local incurrence_se : display %04.2f reg_results["se", "L_Iin_covenant_violation"]
local incurrence_p = reg_results["pvalue", "L_Iin_covenant_violation"]

if (`incurrence_p' > 0.1) {
	local incurrence_sigstars = ""
} 
if (`incurrence_p' < 0.1) {
	local incurrence_sigstars = "*"
}
if (`incurrence_p' < 0.05) {
	local incurrence_sigstars = "**"
}
if (`incurrence_p' < 0.01) {
	local incurrence_sigstars = "***"
}

local maintenance_b : display %04.2f reg_results["b", "L_Min_covenant_violation"]
local maintenance_se : display %04.2f reg_results["se", "L_Min_covenant_violation"]
local maintenance_p = reg_results["pvalue", "L_Min_covenant_violation"]

if (`maintenance_p' > 0.1) {
	local maintenance_sigstars = ""
} 
if (`maintenance_p' < 0.1) {
	local maintenance_sigstars = "*"
}
if (`maintenance_p' < 0.05) {
	local maintenance_sigstars = "**"
}
if (`maintenance_p' < 0.01) {
	local maintenance_sigstars = "***"
}
local N = e(N)
local r2 : display %9.2f  e(r2)

* H0: Incurrence = Maintenance (results stored in r(estimate) and r(p))
lincom L_Min_covenant_violation - L_Iin_covenant_violation
local estimate = r(estimate)
local p: display %9.3f r(p)

// Put results into table in Word Document 
putdocx table table9a(4,4) = ("`incurrence_b'`incurrence_sigstars'")
putdocx table table9a(5,4) = ("(`incurrence_se')")
putdocx table table9a(6,4) = ("`maintenance_b'`maintenance_sigstars'")
putdocx table table9a(7,4) = ("(`maintenance_se')")
putdocx table table9a(9,4) = (`N')
putdocx table table9a(10,4) = (`r2')
putdocx table table9a(11,4) = ("Yes")
putdocx table table9a(12,4) = ("Yes")
putdocx table table9a(13,4) = ("Yes")
putdocx table table9a(14,4) = ("No")
putdocx table table9a(15,4) = ("No")
putdocx table table9a(16,4) = (`estimate')
putdocx table table9a(17,4) = (`p')


// Column (4) ------------------------------------------------------------------
// Regression: 
reghdfe `LHS' L_Iin_covenant_violation L_Min_covenant_violation (L_incurrence L_maintenance)##c.(`controls') if `conditions', ///
			  absorb(xdim L_incurrence#qdate L_maintenance#qdate) cluster(xdim qdate) 
	
// Store results 
matrix reg_results = r(table)
local incurrence_b : display %04.2f reg_results["b", "L_Iin_covenant_violation"]
local incurrence_se : display %04.2f reg_results["se", "L_Iin_covenant_violation"]
local incurrence_p = reg_results["pvalue", "L_Iin_covenant_violation"]

if (`incurrence_p' > 0.1) {
	local incurrence_sigstars = ""
} 
if (`incurrence_p' < 0.1) {
	local incurrence_sigstars = "*"
}
if (`incurrence_p' < 0.05) {
	local incurrence_sigstars = "**"
}
if (`incurrence_p' < 0.01) {
	local incurrence_sigstars = "***"
}

local maintenance_b : display %04.2f reg_results["b", "L_Min_covenant_violation"]
local maintenance_se : display %04.2f reg_results["se", "L_Min_covenant_violation"]
local maintenance_p = reg_results["pvalue", "L_Min_covenant_violation"]

if (`maintenance_p' > 0.1) {
	local maintenance_sigstars = ""
} 
if (`maintenance_p' < 0.1) {
	local maintenance_sigstars = "*"
}
if (`maintenance_p' < 0.05) {
	local maintenance_sigstars = "**"
}
if (`maintenance_p' < 0.01) {
	local maintenance_sigstars = "***"
}
local N = e(N)
local r2 : display %9.2f  e(r2)

* H0: Incurrence = Maintenance (results stored in r(estimate) and r(p))
lincom L_Min_covenant_violation - L_Iin_covenant_violation
local estimate = r(estimate)
local p: display %9.3f r(p)

// Put results into table in Word Document 
putdocx table table9a(4,5) = ("`incurrence_b'`incurrence_sigstars'")
putdocx table table9a(5,5) = ("(`incurrence_se')")
putdocx table table9a(6,5) = ("`maintenance_b'`maintenance_sigstars'")
putdocx table table9a(7,5) = ("(`maintenance_se')")
putdocx table table9a(9,5) = (`N')
putdocx table table9a(10,5) = (`r2')
putdocx table table9a(11,5) = ("Yes")
putdocx table table9a(12,5) = ("Yes")
putdocx table table9a(13,5) = ("Yes")
putdocx table table9a(14,5) = ("Yes")
putdocx table table9a(15,5) = ("Yes")
putdocx table table9a(16,5) = (`estimate')
putdocx table table9a(17,5) = (`p')


// Table Setup (end) -----------------------------------------------------------
putdocx table table9a(1/17,2/5), halign(center)
putdocx table table9a(.,1), width(3 in)

* Number formatting
putdocx table table9a(4,2/5), nformat(%04.2f)
putdocx table table9a(5,2/5), nformat(%04.2f)
putdocx table table9a(6,2/5), nformat(%04.2f)
putdocx table table9a(7,2/5), nformat(%04.2f)
putdocx table table9a(9,2/5), nformat(%9.0fc)
putdocx table table9a(10,2/5), nformat(%9.3g)
putdocx table table9a(16,2/5), nformat(%05.3f)
putdocx table table9a(17,2/5), nformat(%9.3g)

* Table formatting
putdocx table table9a(.,.), font("Times New Roman", 9)	
	
// Export Table 9A
putdocx save "$tables_path/Table9A.docx", replace

	
/*------------------------------------------------------------------------------
								 Table 9B
------------------------------------------------------------------------------*/
// Import Table 9B data --------------------------------------------------------	
use "$data_path/Table9B_Adjusted_EBITDA.dta", clear


// Table Setup -----------------------------------------------------------------
putdocx clear 
putdocx begin 
putdocx paragraph 
putdocx table table9b = (17,5), border(insideV, nil) border(insideH, nil) border(left, nil) border(right, nil)

* Left margin
putdocx table table9b(4,1) = ("Incurrence covenant violation")
putdocx table table9b(6,1) = ("Maintenance covenant violation")
putdocx table table9b(9,1) = ("Observations")
putdocx table table9b(10,1) = ("R-squared")
putdocx table table9b(11,1) = ("Firm FE")
putdocx table table9b(12,1) = ("Quarter FE")
putdocx table table9b(13,1) = ("Controls")
putdocx table table9b(14,1) = ("Controls*Cov-type")
putdocx table table9b(15,1) = ("Quarter FE*Cov-type")
putdocx table table9b(16,1) = ("H0: Maintenance = Incurrence")
putdocx table table9b(17,1) = ("p-value")

* Top margin
putdocx table table9b(1,2), colspan(2)
putdocx table table9b(1,2) = ("Using adjusted EBITDA")
putdocx table table9b(1,3), colspan(2)
putdocx table table9b(1,3) = ("Using GAAP EBITDA on adj. EBITDA sample")

putdocx table table9b(2,2) = ("(1)")
putdocx table table9b(2,3) = ("(2)")
putdocx table table9b(2,4) = ("(3)")
putdocx table table9b(2,5) = ("(4)")
putdocx table table9b(2,.), border(bottom)


// Define Regression Specifications --------------------------------------------
local trim_scalar = 2
local i = 1 
local LHS "capex_capital_ratio_tr"

local controls0   "L_macroq_tr L_logatq_tr cashflowq_tr" 
local dd_controls " L_DD_Total_final_tr L_DD_Total_final_sq_tr"
local controls    "`controls0' `dd_controls'"

local cond0 "L.dealscan <= 1"
local cond1 "_b1_diff_std <= 2 & _b2_diff_std <= 2"
local cond2 "(!mi(lev_limit) | !mi(intcov_limit) | !mi(Ilev_limit) | !mi(Iintcov_limit))"
local conditions "`cond0' & `cond1' & `cond2'"


// Column (1) ------------------------------------------------------------------
// Regression: 
reghdfe `LHS' L_Iin_covenant_violation L_Min_covenant_violation `controls' L_incurrence L_maintenance if `conditions', ///
			  absorb(xdim qdate) cluster(qdate)  

// Store results 
matrix reg_results = r(table)
local incurrence_b : display %04.2f reg_results["b", "L_Iin_covenant_violation"]
local incurrence_se : display %04.2f reg_results["se", "L_Iin_covenant_violation"]
local incurrence_p = reg_results["pvalue", "L_Iin_covenant_violation"]

if (`incurrence_p' > 0.1) {
	local incurrence_sigstars = ""
} 
if (`incurrence_p' < 0.1) {
	local incurrence_sigstars = "*"
}
if (`incurrence_p' < 0.05) {
	local incurrence_sigstars = "**"
}
if (`incurrence_p' < 0.01) {
	local incurrence_sigstars = "***"
}

local maintenance_b : display %04.2f reg_results["b", "L_Min_covenant_violation"]
local maintenance_se : display %04.2f reg_results["se", "L_Min_covenant_violation"]
local maintenance_p = reg_results["pvalue", "L_Min_covenant_violation"]

if (`maintenance_p' > 0.1) {
	local maintenance_sigstars = ""
} 
if (`maintenance_p' < 0.1) {
	local maintenance_sigstars = "*"
}
if (`maintenance_p' < 0.05) {
	local maintenance_sigstars = "**"
}
if (`maintenance_p' < 0.01) {
	local maintenance_sigstars = "***"
}
local N = e(N)
local r2 : display %9.2f  e(r2)

* H0: Incurrence = Maintenance (results stored in r(estimate) and r(p))
lincom L_Min_covenant_violation - L_Iin_covenant_violation
local estimate = r(estimate)
local p: display %9.3f r(p)

// Put results into table in Word Document 
putdocx table table9b(4,2) = ("`incurrence_b'`incurrence_sigstars'")
putdocx table table9b(5,2) = ("(`incurrence_se')")
putdocx table table9b(6,2) = ("`maintenance_b'`maintenance_sigstars'")
putdocx table table9b(7,2) = ("(`maintenance_se')")
putdocx table table9b(9,2) = (`N')
putdocx table table9b(10,2) = (`r2')
putdocx table table9b(11,2) = ("Yes")
putdocx table table9b(12,2) = ("Yes")
putdocx table table9b(13,2) = ("Yes")
putdocx table table9b(14,2) = ("No")
putdocx table table9b(15,2) = ("No")
putdocx table table9b(16,2) = (`estimate')
putdocx table table9b(17,2) = (`p')
	

// Column (2) ------------------------------------------------------------------
// Regression: 	
reghdfe `LHS' L_Iin_covenant_violation L_Min_covenant_violation (L_incurrence L_maintenance)##c.(`controls') if `conditions', ///
			  absorb(xdim L_incurrence#qdate L_maintenance#qdate) cluster(qdate) 

// Store results 
matrix reg_results = r(table)
local incurrence_b : display %04.2f reg_results["b", "L_Iin_covenant_violation"]   
local incurrence_se : display %04.2f reg_results["se", "L_Iin_covenant_violation"]
local incurrence_p = reg_results["pvalue", "L_Iin_covenant_violation"]

if (`incurrence_p' > 0.1) {
	local incurrence_sigstars = ""
} 
if (`incurrence_p' < 0.1) {
	local incurrence_sigstars = "*"
}
if (`incurrence_p' < 0.05) {
	local incurrence_sigstars = "**"
}
if (`incurrence_p' < 0.01) {
	local incurrence_sigstars = "***"
}

local maintenance_b : display %04.2f reg_results["b", "L_Min_covenant_violation"]
local maintenance_se : display %04.2f reg_results["se", "L_Min_covenant_violation"]
local maintenance_p = reg_results["pvalue", "L_Min_covenant_violation"]

if (`maintenance_p' > 0.1) {
	local maintenance_sigstars = ""
} 
if (`maintenance_p' < 0.1) {
	local maintenance_sigstars = "*"
}
if (`maintenance_p' < 0.05) {
	local maintenance_sigstars = "**"
}
if (`maintenance_p' < 0.01) {
	local maintenance_sigstars = "***"
}
local N = e(N)
local r2 : display %9.2f  e(r2)

* H0: Incurrence = Maintenance (results stored in r(estimate) and r(p))
lincom L_Min_covenant_violation - L_Iin_covenant_violation
local estimate = r(estimate)
local p: display %9.3f r(p)

// Put results into table in Word Document 
putdocx table table9b(4,3) = ("`incurrence_b'`incurrence_sigstars'")
putdocx table table9b(5,3) = ("(`incurrence_se')")
putdocx table table9b(6,3) = ("`maintenance_b'`maintenance_sigstars'")
putdocx table table9b(7,3) = ("(`maintenance_se')")
putdocx table table9b(9,3) = (`N')
putdocx table table9b(10,3) = (`r2')
putdocx table table9b(11,3) = ("Yes")
putdocx table table9b(12,3) = ("Yes")
putdocx table table9b(13,3) = ("Yes")
putdocx table table9b(14,3) = ("Yes")
putdocx table table9b(15,3) = ("Yes")
putdocx table table9b(16,3) = (`estimate')
putdocx table table9b(17,3) = (`p')
 
 
// Import Table 9B data	--------------------------------------------------------	
use "$data_path/Table9B_GAAP_EBITDA.dta", clear


// Column (3) ------------------------------------------------------------------
// Regression: 
reghdfe `LHS' L_Iin_covenant_violation L_Min_covenant_violation `controls' L_incurrence L_maintenance if `conditions' & column6_sample == 1, ///
			  absorb(xdim qdate) cluster(qdate) 

// Store results 
matrix reg_results = r(table)
local incurrence_b : display %04.2f reg_results["b", "L_Iin_covenant_violation"]
local incurrence_se : display %04.2f reg_results["se", "L_Iin_covenant_violation"]
local incurrence_p = reg_results["pvalue", "L_Iin_covenant_violation"]

if (`incurrence_p' > 0.1) {
	local incurrence_sigstars = ""
} 
if (`incurrence_p' < 0.1) {
	local incurrence_sigstars = "*"
}
if (`incurrence_p' < 0.05) {
	local incurrence_sigstars = "**"
}
if (`incurrence_p' < 0.01) {
	local incurrence_sigstars = "***"
}

local maintenance_b : display %04.2f reg_results["b", "L_Min_covenant_violation"]
local maintenance_se : display %04.2f reg_results["se", "L_Min_covenant_violation"]
local maintenance_p = reg_results["pvalue", "L_Min_covenant_violation"]

if (`maintenance_p' > 0.1) {
	local maintenance_sigstars = ""
} 
if (`maintenance_p' < 0.1) {
	local maintenance_sigstars = "*"
}
if (`maintenance_p' < 0.05) {
	local maintenance_sigstars = "**"
}
if (`maintenance_p' < 0.01) {
	local maintenance_sigstars = "***"
}
local N = e(N)
local r2 : display %9.2f  e(r2)

* H0: Incurrence = Maintenance (results stored in r(estimate) and r(p))
lincom L_Min_covenant_violation - L_Iin_covenant_violation
local estimate = r(estimate)
local p: display %9.3f r(p)

// Put results into table in Word Document 
putdocx table table9b(4,4) = ("`incurrence_b'`incurrence_sigstars'")
putdocx table table9b(5,4) = ("(`incurrence_se')")
putdocx table table9b(6,4) = ("`maintenance_b'`maintenance_sigstars'")
putdocx table table9b(7,4) = ("(`maintenance_se')")
putdocx table table9b(9,4) = (`N')
putdocx table table9b(10,4) = (`r2')
putdocx table table9b(11,4) = ("Yes")
putdocx table table9b(12,4) = ("Yes")
putdocx table table9b(13,4) = ("Yes")
putdocx table table9b(14,4) = ("No")
putdocx table table9b(15,4) = ("No")
putdocx table table9b(16,4) = (`estimate')
putdocx table table9b(17,4) = (`p')

		
	
// Column (4) ------------------------------------------------------------------
// Regression: 		
reghdfe `LHS' L_Iin_covenant_violation L_Min_covenant_violation (L_incurrence L_maintenance)##c.(`controls') if `conditions' & column7_sample == 1, ///
			  absorb(xdim L_incurrence#qdate L_maintenance#qdate) cluster(qdate) 
	
// Store results 
matrix reg_results = r(table)
local incurrence_b : display %04.2f reg_results["b", "L_Iin_covenant_violation"]   
local incurrence_se : display %04.2f reg_results["se", "L_Iin_covenant_violation"]
local incurrence_p = reg_results["pvalue", "L_Iin_covenant_violation"]

if (`incurrence_p' > 0.1) {
	local incurrence_sigstars = ""
} 
if (`incurrence_p' < 0.1) {
	local incurrence_sigstars = "*"
}
if (`incurrence_p' < 0.05) {
	local incurrence_sigstars = "**"
}
if (`incurrence_p' < 0.01) {
	local incurrence_sigstars = "***"
}

local maintenance_b : display %04.2f reg_results["b", "L_Min_covenant_violation"]
local maintenance_se : display %04.2f reg_results["se", "L_Min_covenant_violation"]
local maintenance_p = reg_results["pvalue", "L_Min_covenant_violation"]

if (`maintenance_p' > 0.1) {
	local maintenance_sigstars = ""
} 
if (`maintenance_p' < 0.1) {
	local maintenance_sigstars = "*"
}
if (`maintenance_p' < 0.05) {
	local maintenance_sigstars = "**"
}
if (`maintenance_p' < 0.01) {
	local maintenance_sigstars = "***"
}
local N = e(N)
local r2 : display %9.2f  e(r2)

* H0: Incurrence = Maintenance (results stored in r(estimate) and r(p))
lincom L_Min_covenant_violation - L_Iin_covenant_violation
local estimate = r(estimate)
local p: display %9.3f r(p)

// Put results into table in Word Document 
putdocx table table9b(4,5) = ("`incurrence_b'`incurrence_sigstars'")
putdocx table table9b(5,5) = ("(`incurrence_se')")
putdocx table table9b(6,5) = ("`maintenance_b'`maintenance_sigstars'")
putdocx table table9b(7,5) = ("(`maintenance_se')")
putdocx table table9b(9,5) = (`N')
putdocx table table9b(10,5) = (`r2')
putdocx table table9b(11,5) = ("Yes")
putdocx table table9b(12,5) = ("Yes")
putdocx table table9b(13,5) = ("Yes")
putdocx table table9b(14,5) = ("Yes")
putdocx table table9b(15,5) = ("Yes")
putdocx table table9b(16,5) = (`estimate')
putdocx table table9b(17,5) = (`p')
	

// Table Setup (end) -----------------------------------------------------------
putdocx table table9b(1/17,2/5), halign(center)
putdocx table table9b(.,1), width(3 in)

* Number formatting
putdocx table table9b(4,2/5), nformat(%04.2f)
putdocx table table9b(5,2/5), nformat(%04.2f)
putdocx table table9b(6,2/5), nformat(%04.2f)
putdocx table table9b(7,2/5), nformat(%04.2f)
putdocx table table9b(9,2/5), nformat(%9.0fc)
putdocx table table9b(10,2/5), nformat(%9.3g)
putdocx table table9b(16,2/5), nformat(%05.3f)
putdocx table table9b(17,2/5), nformat(%9.3g)

* Table formatting
putdocx table table9b(.,.), font("Times New Roman", 9)

// Export Table 9B
putdocx save "$tables_path/Table9B.docx", replace


